home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Yerk 3.64 / System source / Proc < prev    next >
Text File  |  1993-06-05  |  4KB  |  106 lines

  1. \ A pair of words designed to enable Yerk words to be called with a
  2. \  Pascal lookalike stack. Useful when a routine is passed to a Tool-
  3. \  box entry for asynchronous routines.
  4. \  Terminology: Any such Pascal lookalike is called a proc word
  5. \ 10/15/84  RW
  6. \ 12/22/85  CBD Rewrote PSTART, (Hyperdrive fix)
  7. \  8/31/88    rfl    took out meaningless nop in pstart
  8. \  4/01/90    rfl    took out adda.l #$48,a3 since no longer have old yerk header
  9. \ 12/30/90    rfl stack now 3000, and 300 for method stack
  10. \  6/07/91    rfl yerk base now 2c from a5
  11. \ 10/26/91    rfl    increased stack to 7000 for use with system 7
  12. \  4/11/92    rfl    flush cache on :proc if necessary
  13. \  5/02/92    rfl    changed the way a5,a3 are recovered..stored at startup
  14. \                  in a resource called MYA5.
  15. \  4/24/93    rfl    once again, changed the way a5,a3 are recovered. The resource
  16. \                  method moves memory and you don't want that if it is
  17. \                  called by interrupt. So now, to be safe, all procwords
  18. \                  defined in your application will be inited with a5,a3 at
  19. \                  startup time by sticking 'initProcs' into your startup word.
  20. \ 5/18/93    rfl    protected initproc from an assembly proc
  21. Hex
  22.  
  23. 0 value pstartLen
  24.  
  25. \ PSTART - Converts Pascal stack format to our Forth stack format.
  26. \            N.B. - VERY IMPORTANT!!! - This word will never be
  27. \            directly executed. Instead the code will be CMOVE'd
  28. \            into place during the execution of PROC and executed by
  29. \            the routine active via JSR.
  30.  
  31. Create Pstart <[
  32.     600c w,            \         bra.s        next        \ jump over data area
  33.     'type proc ,    \                                \ marker to identify it as proc
  34.     0      ,            \ data                            \ a5 will be here
  35.     0      ,            \                                 \ a3 will be here
  36.     204E w,            \ next    movea.l    a6,a0            \ store return stack ptr
  37.     2C4F w,            \     movea.l    a7,a6                \ save parm stack
  38.     9DFC w, 2328 ,    \     suba.l    #9000,a6            \ allow stack to have 7000 bytes
  39.     2D08 w,            \     move.l    a0,-(a6)            \ save old return stack ptr here
  40.     2D1F w,            \     move.l    (a7)+,-(a6)            \ save return address here
  41.     48E63F1C ,        \     movem.l    d2-d7/a3-a5,-(a6)    \ save these registers, including a5
  42.                                                     \  and a3
  43.     49faffe4 ,        \    lea        data(pc),a4            \ point to a5 data area
  44.     2a5c w,            \    movea.l    (a4)+,a5            \ get a5
  45.     2654 w,            \    movea.l    (a4),a3                \ get a3, ptr to yerk base
  46.  
  47.     2A0E w,            \    move.l    a6,d5                \ let ret stack have only 300
  48.     0485 w, 1f4 ,    \    subi.l    #500,d5                \ and give method stack the rest
  49.     49FA0006 ,        \    lea        6(pc),a4               \ load a4 with ptr to routine
  50. next,
  51.  
  52. \ PEXIT - This code is equally tricky as the above PSTART. This
  53. \          restores the old A6 register and then jumps back to the
  54. \          return location from which the word was called. This
  55. \          code word will be invoked through the colon code, but
  56. \          colon-code will never see it again.
  57. Create P;s <[
  58.     4CDE38FC ,        \ movem.l    (a6)+,d2-d7/a3-a5    \ restore a3 and a5 especially
  59.     205E w,            \ movea.l    (a6)+,a0
  60.     2C5E w,            \ movea.l    (a6)+,a6
  61.     4ED0 w,            \ jmp        (a0)
  62.  
  63. Decimal
  64. ' P;s nfa ' Pstart -  docs 2* -  -> pstartLen    \ if documentation on, subtract 2.
  65.  
  66. \ build a word that looks like a Pascal procedure at its PFA
  67. : :PROC
  68.     ?exec create    \  build hdr, cfa
  69.     ' pstart here pstartLen allot   pstartLen cMove
  70.     cflush    \ flush caches on appropriate machines
  71.     ]> ;    \ enter compilation state
  72.     
  73. : ;PROC   Compile P;s  [Compile] <[   ;  Immediate
  74.  
  75. \ don't assume proc word is always a :proc def..could be assembly
  76. : initProc ( 'cproc -- ) >body dup 2+ @ $ 70726f63 =        \ check for 'proc'
  77.     IF 6 + geta3a5 rot swap over ! 4+ ! ELSE drop THEN ;
  78.  
  79. : (initProcs) { theCfa arg -- } theCfa 6 + @ 'type proc =    \ check for marker
  80.     IF theCfa initProc ." initProc: " theCfa >name id. cr THEN ;            \ it's a procword, so init it
  81.  
  82. \ This word will initialize each procword in your program (at startup time)
  83. : initProcs 'c (initProcs) 0 trav ;
  84.  
  85. \ **** STACK LAYOUT DURING PROCEDURE
  86. \               |
  87. \ method stack  |
  88. \               | <---  d5
  89. \ ______________|
  90. \               |
  91. \ return stack  | <---  a6
  92. \ ______________|
  93. \               |
  94. \ data stack    | <---  A7'  = A7+4 (NEW DATA STACK)
  95. \               | <---- a7
  96. \               |
  97. \               |
  98. \ A6            |
  99. \ (A7) RETURN   |
  100. \ D,A REGISTERS | <---  A6'  = A7-3000 (NEW RETURN STACK)
  101. \               |
  102. \               |
  103. \               | <---  D5'  = A6'-300 (NEW METHODS STACK)
  104.  
  105.